<template>
  <div class="dialog">
    <el-dialog
      title="手动调整生长进度"
      :visible.sync="showDialog"
      width="30%"
      @close="close"
    >
      <el-form :model="formData">
        <el-form-item label="实际生长阶段:">
          <el-select
            v-model="formData.growthPhaseNo"
            placeholder="请选择实际生长阶段"
            style="width: 100%"
          >
            <el-option
              v-for="(item, index) in growthList"
              :key="index"
              :label="item.growthPhaseName"
              :value="item.growthPhaseNo"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="阶段天数:">
          <!-- <el-date-picker
            v-model="formData.endDate"
            type="date"
            placeholder="选择日期"
            style="width: 100%"
          /> -->
          <el-input v-model="formData.cycle" placeholder="请输入实际天数" />
        </el-form-item>
      </el-form>
      <div class="submit-box">
        <el-button type="primary" class="submit" @click="onSubmit">
          确定
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import configurationApi from "@/api/digital-production/conservation-model/configuration/index";
// import moment from "moment";
export default {
  name: "",
  components: {},
  props: {
    show: {
      type: Boolean,
      default: false
    },
    batchNo: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      showDialog: this.show,
      formData: { growthPhaseNo: "", endDate: "" },
      growthList: [] // 生长周期
    };
  },
  watch: {
    show(v) {
      this.showDialog = v;
    }
  },
  created() {},
  mounted() {},
  methods: {
    getData(data) {
      this.growthList = [];
      if (data.length > 0) {
        data.forEach((element) => {
          if (element.realDurationDays) {
            this.growthList.push(element);
          }
          if (element.status === 1) {
            this.formData.growthPhaseNo = element.growthPhaseNo;
          }
        });
      }
      // console.log(data)
      // console.log(this.growthList)
      // if (data.length === this.growthList.length) {
      //   this.growthList = [];
      // }
    },
    onSubmit() {
      // this.formData.cycle = moment(this.formData.endDate).format(
      //   "YYYY-MM-DD"
      // );
      this.formData.batchNo = this.batchNo;
      configurationApi.addBatchStage(this.formData).then((res) => {
        if (res.code === 1) {
          this.$message.success('修改成功');
          this.$router.push({ name: 'crop-model-config' })
          this.close();
        } else {
          this.$message.error('修改失败');
        }
      });
    },
    close() {
      this.$emit("closeDialog");
    }
  }
};
</script>

<style scoped lang="scss">
.btns-box {
  display: flex;
  align-items: center;
  padding: 5px;
  > div {
    padding: 0 10px;
    display: flex;
    align-items: center;
    cursor: pointer;
  }
}
.input-label {
  text-align: right;
  font-size: 16px;
}
.submit-box {
  width: 100%;
  padding: 0 20px;
  text-align: right;
  .submit {
    background-color: rgba(0, 110, 145, 1);
  }
}
::v-deep .el-form .el-form-item__label {
  color: #333333 !important;
}
::v-deep .el-input__inner {
  background: rgba(255, 255, 255, 0) !important;
  color: #333333 !important;
}
::v-deep .el-form-item {
  display: flex;
}
::v-deep .el-form-item__content {
  width: 100%;
}
::v-deep .el-form .el-form-item__label {
  width: 150px;
}
</style>
